package cn.com.yusys.yusp.admin.service;

import cn.com.yusys.yusp.admin.domain.AdminSmDataFilterSub;
import cn.com.yusys.yusp.admin.repository.mapper.AdminSmDataFilterSubMapper;
import cn.com.yusys.yusp.commons.mapper.CommonMapper;
import cn.com.yusys.yusp.commons.mapper.QueryModel;
import cn.com.yusys.yusp.commons.service.CommonService;
import cn.com.yusys.yusp.commons.util.DateUtil;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class AdminSmDataFilterSubService extends CommonService {
	@Autowired
	private AdminSmDataFilterSubMapper mapper;

	@SuppressWarnings("rawtypes")
    @Override
	protected CommonMapper getMapper() {
		return this.mapper;
	}

	@SuppressWarnings("rawtypes")
    public int deleteByFilterId(Map param) {

		return this.mapper.deleteByFilterId(param);
	}

	@Override
	public int insert(Object record) {
		AdminSmDataFilterSub adminSmDataFilter = (AdminSmDataFilterSub) record;
		adminSmDataFilter.setLastChgDt(DateUtil.formatDateByDef());
		adminSmDataFilter.setLastChgUsr("admin");
		return this.insert(getMapper(), record);
	}

	/*
	 * 重写 ，为支撑页面模糊查询
	 */
	@Override
	public <T> List<T> selectByModel(QueryModel model) {
		// 模糊条件
		if (model.getCondition().containsKey("sqlName")) {
			model.getCondition().put("sqlName", "%" + model.getCondition().get("sqlName") + "%");
		}
		if (model.getCondition().containsKey("sqlString")) {
			model.getCondition().put("sqlString", "%" + model.getCondition().get("sqlString") + "%");
		}

		return this.selectByModel(getMapper(), model);
	}
}
